#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
@AUTHOR: tyc
@VERSION: 1.0.0
@DESCRIPTION: 爬取图片
@time: 2021-07-02 22:49:45 
"""
import requests
import re


def print_img_url(url):
    resp = requests.get("http://simpledesktops.com/browse/")
    obj = re.compile(r'<img src="(?P<img_url>.*?).295x184_q100.png"', re.S)
    for item in re.finditer(obj, resp.text):
        img_url = item.group('img_url')
        img_name = img_url.split('/')[-1]
        with open(f"imgs/{img_name}", "wb") as f:
            f.write(requests.get(img_url).content)
        print(f'{img_name} 下载完成')


if __name__ == '__main__':
    for i in range(1, 2):
        url = f'https://simpledesktops.com/browse/{i}/'
        print_img_url(url)
